﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace DBLayer
{
    public class DBConnection
    {

        private static string ConnectionString = Properties.Settings.Default.ConnectionString;

        private static DBConnection instance = null;
        private static SqlConnection sqlconn;

        //Establish connection to the DB
        private DBConnection()
        {
            sqlconn = new SqlConnection(Properties.Settings.Default.ConnectionString);
        }

        //create instance of the db class
        public static DBConnection getConnection()
        {
            if (instance == null)
            {
                instance = new DBConnection();
            }

            return instance;

        }

        public static void closeConnection()
        {
            try
            {
                sqlconn.Close();
            }
            catch (Exception e)
            {

                Console.WriteLine("could not close connection");
                Console.WriteLine(e.Message);
            }
        }

        // get connection to the database
        public SqlConnection getSQLConnection()
        {
            return sqlconn;
        }

        public static void openConnection()
        {
            try
            {
                sqlconn.Open();
                Console.WriteLine("connection Opened");
            }
            catch (Exception e)
            {
                Console.WriteLine("Connection didnt open");
                Console.WriteLine(e.Message);
            }

        }

        public void startTransaction()
        {

        }
    }
}